home *** CD-ROM | disk | FTP | other *** search
- /*--------------------------------------------------------------------------*/
- /* */
- /* */
- /* ------------ Bit-Bucket Software <no-Inc> */
- /* \ 10001101 / Writers and Distributors of */
- /* \ 011110 / No-Cost<no-tm> Software. */
- /* \ 1011 / */
- /* ------ */
- /* */
- /* Copyright (C) 1987, 1988, 1989 by Robert Hartman and Vincent Perriello */
- /* */
- /* */
- /* This module was originally written by Bob Hartman */
- /* */
- /* */
- /* BinkleyTerm "Spawn" module */
- /* */
- /* */
- /* For complete details of the licensing restrictions, please refer */
- /* to the License agreement, which is published in its entirety in */
- /* the MAKEFILE and BT.C, and also contained in the file LICENSE.210. */
- /* */
- /* USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE */
- /* BINKLEYTERM LICENSING AGREEMENT. IF YOU DO NOT FIND THE TEXT OF */
- /* THIS AGREEMENT IN ANY OF THE AFOREMENTIONED FILES, OR IF YOU DO */
- /* NOT HAVE THESE FILES, YOU SHOULD IMMEDIATELY CONTACT THE AUTHORS */
- /* AT THE ADDRESSES LISTED BELOW. IN NO EVENT SHOULD YOU PROCEED TO */
- /* USE THIS FILE WITHOUT HAVING ACCEPTED THE TERMS OF THE */
- /* BINKLEYTERM LICENSING AGREEMENT, OR SUCH OTHER AGREEMENT AS YOU */
- /* ARE ABLE TO REACH WITH THE AUTHORS. */
- /* */
- /* */
- /* The Authors can be reached at the following addresses: */
- /* */
- /* Robert C. Hartman Vincent E. Perriello */
- /* Spark Software VEP Software */
- /* 427-3 Amherst Street 111 Carroll Street */
- /* CS2032, Suite 232 Naugatuck, CT 06770 */
- /* Nashua, NH 03061 */
- /* */
- /* FidoNet 1:132/101 FidoNet 1:141/491 */
- /* Data (603) 888-8179 Data (203) 729-7569 */
- /* */
- /* Please feel free to contact us at any time to share your comments */
- /* about our software and/or licensing policies. */
- /* */
- /*--------------------------------------------------------------------------*/
-
- #include <stdio.h>
- #include <time.h>
- #include <stdlib.h>
- #include <process.h>
- #include <string.h>
- #include <dos.h>
-
- #ifdef __TURBOC__
- #include <dir.h>
- #include <mem.h>
- #else
- #include <direct.h>
- #include <memory.h>
- #endif
-
- #include "com.h"
- #include "xfer.h"
- #include "zmodem.h"
- #include "keybd.h"
- #include "sbuf.h"
- #include "sched.h"
- #include "externs.h"
- #include "prototyp.h"
-
- #include <stdlib.h> /*PLF extern char **environ; */
-
- #ifdef OS_2 /*PLF Fri 05-05-1989 05:19:04 */
-
- #define INCL_DOS
- #include <os2.h>
-
- void b_spawn(char *cmd)
- {
- char this_dir[80];
- char *comspec;
-
- getcwd (this_dir, 79);
- if( cmd )
- system(cmd);
- else{
- if(comspec = getenv("COMSPEC"))
- spawnlp(P_WAIT, comspec, comspec, NULL);
- }
- DosSelectDisk(*this_dir - 'A' + 1); /* in OS/2, drive 1=A, 2=B etc */
- chdir(this_dir);
- }
-
- #else /*PLF Fri 05-05-1989 05:19:13 */
-
- void b_spawn (cmd_str)
- char *cmd_str;
- {
- char *p, *p1;
- char **envp, *env, *save, **vp;
- char this_dir[80];
- int ecount;
- unsigned j;
-
- /* Save where we are */
- getcwd (this_dir, 79);
-
- if ((p = getenv ("COMSPEC")) == NULL)
- p = "COMMAND.COM";
-
- if (swapdir == NULL)
- {
- if (cmd_str != NULL)
- system (cmd_str);
- else
- spawnlp (P_WAIT, p, p, NULL);
- }
- else
- {
- /*
- * The following lines are really wierd. Basically, we need to
- * pass a valid environment to DOS when we do the spawn. Unfortunately,
- * it is very likely that we have changed the environment (like when
- * we alter the prompt), and therefore we have to make yet another
- * copy of it, and make sure it can be paragraph aligned. We pass the
- * offset in paragraph format so it can just be added to the DS in
- * order to get the actual paragraph location.
- */
- ecount = 0;
- envp = environ;
-
- /* Count the chars in the environment */
- for (vp = envp; *vp; ecount += strlen (*vp++) + 1)
- ;
-
- /* Add some fudge for nulls, etc */
- ecount += 5;
-
- /* Allocate space for a copy of the environment to be para aligned */
- save = env = malloc (ecount + 15);
-
- /* Align on a paragraph boundary - yucky, but it works */
- *((unsigned int *)&env) = (*((unsigned int *)&env)+0xf) & (~0xf);
-
- p1 = env;
-
- /* Copy old environment to the new */
- for (vp = envp; *vp; vp++)
- p1 = strchr(strcpy(p1, *vp), '\0') + 1;
- *p1++ = '\0';
- *p1++ = '\0';
-
- /* Now actually call our code that does the swapping */
- swapper (p, swapdir, strlen (cmd_str), cmd_str, ((unsigned) (env)) >> 4);
-
- /* Free the stuff we allocated */
- free (save);
- }
-
- /* Go back to the proper directory */
- chdir (this_dir);
- #ifdef __TURBOC__
- setdisk ((unsigned) (this_dir[0] - 'A' + 1));
- #else
- _dos_setdrive ((unsigned) (this_dir[0] - 'A' + 1), &j);
- #endif
- }
-
- #endif /*plf Fri 05-05-1989 05:19:21 */